<?php
class LoginAction extends Action{
	public function index(){
		$this->display();
	}
    
	public function login(){
		if(empty($_POST['username']) || empty($_POST['password'])){
			$errmsg = '用户名或密码不能为空!")';
		}
		if(!empty($errmsg)){
			$this->assign('username',$_POST['username']);
			$this->assign('errmsg',$errmsg);
			$this->display('index');
		}else{
			$Suser = M('Suser');
			$vo=$Suser->join("store on suser.suser_id = store.store_mid")
	         ->where("suser_name='".$_POST['username']."' and suser_password='".md5($_POST['password'])."'")
				->find();
			if ($vo){
                //var_dump($vo);
				$_SESSION['suser']['account'] = trim($vo['suser_id']);
                $_SESSION['suser']['store_id'] = trim($vo['store_id']);
				$this->redirect('UserAdmin/index');
			}else{
				$errmsg = '账号或者密码错误!';
				$this->assign('username',$_POST['username']);
		    	$this->assign('errmsg',$errmsg);
			    $this->display('index');
                
			} 
		}
	}
}
?>